package es.controller;


import es.bean.CommonResult;
import es.dto.BaseDto;
import es.dto.ProcurementDto;
import es.service.TenderInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * <p>
 * 中标数据 前端控制器
 * </p>
 *
 * @author mp
 * @since 2024-11-13
 */
@RestController
@RequestMapping("/")
public class TenderInfoController {


    @Resource
    private TenderInfoService tenderInfoService;

    @PostMapping("search/company")
    public CommonResult<Object> searchCompanyName(@RequestBody BaseDto dto){
        if (StringUtils.isBlank(dto.getKey())) {
            return CommonResult.error("请输入关键字");
        }
        if (dto.getSearchType() == null) {
            return CommonResult.error("缺少搜索类型");
        }
        return tenderInfoService.searchCompanyName(dto);
    }

    @PostMapping("search/procurementName")
    public CommonResult<Object> procurementName(@RequestBody BaseDto dto){
        if (StringUtils.isBlank(dto.getKey())) {
            return CommonResult.error("请输入关键字");
        }
        return tenderInfoService.procurementName(dto);
    }

    @PostMapping("getList/procurement")
    public CommonResult<Object> getProcurementList(@RequestBody ProcurementDto dto){
        try {
            return tenderInfoService.getProcurementList(dto);
        } catch (IOException e) {
            e.printStackTrace();
            return CommonResult.error("es查询出错");
        }
    }

}

